#include "pwm.h"

extern TIM_HandleTypeDef htim4;

void SetPWM(uint32_t channel,int16_t value)

{
//    TIM_OC_InitTypeDef sConfigOC;
// 
//    sConfigOC.OCMode = TIM_OCMODE_PWM1;
//    sConfigOC.Pulse = value + 1500;
//    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
//    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
//    HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, channel);
//    HAL_TIM_PWM_Start(&htim4, channel);   
  
    /* Set the Capture Compare Register value */
  switch(channel)
  {
    case TIM_CHANNEL_1:  TIM4->CCR1 = 20000-(value+1500);break;
    case TIM_CHANNEL_2:  TIM4->CCR2 = 20000-(value+1500);break;
    case TIM_CHANNEL_3:  TIM4->CCR3 = 20000-(value+1500);break;
    case TIM_CHANNEL_4:  TIM4->CCR4 = 20000-(value+1500);break;
   default:break;
  }
   
}
void InitPWM(uint32_t channel)

{
    TIM_OC_InitTypeDef sConfigOC;
 
    sConfigOC.OCMode = TIM_OCMODE_PWM1;
    sConfigOC.Pulse = 20000 - 1500;
    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
    HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, channel);
    HAL_TIM_PWM_Start(&htim4, channel);   
}



